Dismiss View Controller after Google Sign In calls methods in App Delegate (iOS / Swift)

您所在的位置:网站首页 how to delegate 答案 Dismiss View Controller after Google Sign In calls methods in App Delegate (iOS / Swift)

Dismiss View Controller after Google Sign In calls methods in App Delegate (iOS / Swift)

2023-12-03 23:12| 来源: 网络整理| 查看: 265

I have implemented Google Sign in on my project, where I have a View Controller for handling logins that is presented modally. The google sign in button calls methods that are in the app delegate.

I want to be able to dismiss the View Controller once the user has signed in, but I'm stuck on how to do this. Image here: https://i.imgur.com/5N89wUb.png

dismiss() can't be called from the app delegate. I tried putting a function in my login view controller that checks if the user is logged in, but this doesn't run as the login process is run async (not to mention a very hacky method)

//Code on the Login VC: override func viewDidLoad() { super.viewDidLoad() //Google Sign in stuff GIDSignIn.sharedInstance()?.presentingViewController = self // Automatically sign in the user. GIDSignIn.sharedInstance()?.restorePreviousSignIn() ... func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

...

GIDSignIn.sharedInstance().clientID = "my-client-id.apps.googleusercontent.com" GIDSignIn.sharedInstance().delegate = self

...

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool { let googleDidHandle = GIDSignIn.sharedInstance().handle(url) let facebookDidHandle = ApplicationDelegate.shared.application(app, open: url, options: options) return facebookDidHandle || googleDidHandle } func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { if let error = error { if (error as NSError).code == GIDSignInErrorCode.hasNoAuthInKeychain.rawValue { print("The user has not signed in before or they have since signed out.") } else { print("\(error.localizedDescription)") } return } guard let idToken = user.authentication.idToken else { fatalError("couldn't get idToken")}// Safe to send to the server googleSignIn(idToken: idToken) }

...

Once the user is signed in, I'd like to close the modally presented view controller, but I don't know how to do that from the app delegate.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3